#pragma once
#include "Channel.h"
#include "Poller.h"

#include <cinttypes>
#include <sys/epoll.h>
#include <vector>

using std::vector;

class EPollPoller : public Poller
{
public:
    EPollPoller(EventLoop *loop);
    ~EPollPoller() override;
    TimeStamp poll(int timeoutMs, ChannelList* activeChannels) override;
    void removeChannel(Channel* channel) override;
    void updateChannel(Channel* channel) override;

private:
    // 填充活跃事件
    void fillActiveChannels(int evtNums, ChannelList *activeChannels) const; 
    static const int kInitEventListSize = 16;
    static const char* optToStr(int op);

    void update(int opt, Channel *channel);

    using EventList = vector<struct epoll_event>;

private:
    int _epollfd;
    EventList _events;

};

